home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / coolcolr.zip / LIBINIT.ASM < prev    next >
Assembly Source File  |  1992-11-17  |  5KB  |  198 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;
  3. ;   libinit.asm
  4. ;
  5. ;   Copyright (c) 1992 Microsoft Corporation.  All Rights Reserved.
  6. ;
  7. ;   General Description:
  8. ;      Library stub to do local init for a dynamic linked library.
  9. ;
  10. ;   Restrictions:
  11. ;      This must be the first object file in the LINK line.  This assures
  12. ;      that the reserved parameter block is at the *base* of DGROUP.
  13. ;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. if1
  16. %out link me first!!
  17. endif
  18.  
  19.         .286
  20.  
  21.         .xlist
  22.         include cmacros.inc
  23.         .list
  24.  
  25. ?PLM=1  ; Pascal calling convention
  26. ?WIN=1  ; Windows prolog/epilog code
  27.  
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. ;
  30. ;   segmentation
  31. ;
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33.  
  34. ifndef SEGNAME
  35.     SEGNAME equ <_TEXT>
  36. endif
  37.  
  38. ifndef WEPSEG
  39.     WEPSEG equ <_WEP>
  40. endif
  41.  
  42. createSeg %SEGNAME, CodeSeg, word, public, CODE
  43. createSeg %WEPSEG, WepCodeSeg, word, public, CODE
  44.  
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46. ;
  47. ;   external functions
  48. ;
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50.  
  51.         externFP LocalInit           ; in KERNEL
  52.         externFP LibMain             ; C code to do DLL init
  53.  
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;
  56. ;   data segment
  57. ;
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59.  
  60. sBegin Data
  61.  
  62.         assumes ds, Data
  63.  
  64. ; stuff needed to avoid the C runtime coming in, and init the Windows
  65. ; reserved parameter block at the base of DGROUP
  66.  
  67.         org 0               ; base of DATA segment!
  68.  
  69.         dd  0               ; so null pointers get 0
  70.  
  71.         dw 5                ; necessary filler for Windows reserved pointers
  72.         dw 5 dup (0)
  73.  
  74. public  __acrtused          ; this prevents the C-runtime from loading.
  75.         __acrtused = 1
  76.  
  77. sEnd Data
  78.  
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;
  81. ;   code segment
  82. ;
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84.  
  85. sBegin CodeSeg
  86.  
  87.         assumes cs, CodeSeg
  88.  
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ; @doc INTERNAL
  91. ;
  92. ; @asm LibInit | Called when DLL is loaded.
  93. ;
  94. ; @reg  CX | Size of heap.
  95. ;
  96. ; @reg  DI | Module handle.
  97. ;
  98. ; @reg  DS | Automatic data segment.
  99. ;
  100. ; @reg  ES:SI | Address of command line (not used).
  101. ;
  102. ; @rdesc AX is TRUE if the load is successful and FALSE otherwise.
  103. ;
  104. ; @comm Registers preserved are SI,DI,DS,BP.  Registers destroyed are
  105. ;       AX,BX,CX,DX,ES,FLAGS.
  106. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  107. cProc LibInit <FAR, PUBLIC, NODATA>, <>
  108.  
  109.         cBegin
  110.  
  111.         ; push frame for LibMain (hModule, wDataSeg, cbHeap, lpszCmdLine)
  112.  
  113.         push di
  114.         push ds
  115.         push cx
  116.         push es
  117.         push si
  118.  
  119.         ; init the local heap (if one is declared in the .def file)
  120.  
  121.         jcxz no_heap
  122.  
  123.         xor ax, ax
  124.         cCall LocalInit, <ds, ax, cx>
  125.         or ax, ax
  126.         je exit
  127.  
  128. no_heap:
  129.         cCall   LibMain
  130.  
  131. exit:
  132.         cEnd
  133.  
  134. sEnd CodeSeg
  135.  
  136. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  137. ;
  138. ;   WEP segment
  139. ;
  140. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  141.  
  142. sBegin  WepCodeSeg
  143.  
  144.         assumes cs, WepCodeSeg
  145.  
  146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  147. ; @doc INTERNAL
  148. ;
  149. ; @asm WEP | This function is called when the DLL is unloaded.
  150. ;
  151. ; @parm WORD | UselessParm | This parameter has no meaning.
  152. ;
  153. ; @comm WARNING: This function is basically useless since you can't call any
  154. ;     kernel function that may cause the LoadModule() code to be reentered.
  155. ;
  156. ;     Following are all the rules to remember when dealing with WEP(). If you
  157. ;     don't follow these you can crash windows (in low memory etc....)
  158. ;
  159. ;     1. WEP() must be in the resident name table
  160. ;              (i.e. exported by name, not by ordinal)
  161. ;
  162. ;              EXPORTS WEP
  163. ;
  164. ;                -- or --
  165. ;
  166. ;              EXPORTS WEP     @1  RESIDENTNAME
  167. ;
  168. ;     2. WEP() must be in a FIXED code segment, not just non-DISCARDABLE
  169. ;
  170. ;     3. Everything WEP() *calls* must also be in a FIXED segment
  171. ;
  172. ;     4. WEP() can't call any linked DLLs
  173. ;
  174. ;     5. WEP() can't call any kernel module managment functions
  175. ;
  176. ;     6. The stack is small, so don't eat a lot of stack
  177. ;
  178. ;     7. a DLL must have a WEP or you will get a RIP in LoadModule()
  179. ;
  180. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  181.  
  182.         assumes ds, nothing
  183.         assumes es, nothing
  184.  
  185. cProc WEP <FAR, PUBLIC, PASCAL>, <>
  186.         ParmW UselessParm
  187.  
  188.         cBegin nogen
  189.  
  190.         mov ax,1
  191.         retf 2
  192.  
  193.         cEnd nogen
  194.  
  195. sEnd WepCodeSeg
  196.  
  197.         end LibInit
  198.